#ifndef __mysetupfunc__
#define __mysetupfunc__

void SetSEGUpUp() {
  // 字段显示复位
  seg05up = true;
  seg03up = true;
  seg06up = false; // 3,5都要让一下

  seg15up = true;
  seg13up = true;
  seg16up = false;

  seg25up = true;
  seg23up = true;
  seg26up = false;

  seg35up = true;
  seg33up = true;
  seg36up = false;

  // 全部上升
  Set0Seg0124(SEG_0_0, true);
  Set0Seg0124(SEG_0_1, true);
  Set0Seg0124(SEG_0_2, true);
  Set0Seg0124(SEG_0_4, true);
  Set0Seg356(true, true, true);
  delay(DELAY_SEC);
  Set1Seg0124(SEG_1_0, true);
  Set1Seg0124(SEG_1_1, true);
  Set1Seg0124(SEG_1_2, true);
  Set1Seg0124(SEG_1_4, true);
  Set1Seg356(true, true, true);
  delay(DELAY_SEC);
  Set2Seg0124(SEG_2_0, true);
  Set2Seg0124(SEG_2_1, true);
  Set2Seg0124(SEG_2_2, true);
  Set2Seg0124(SEG_2_4, true);
  Set2Seg356(true, true, true);
  delay(DELAY_SEC);
  Set3Seg0124(SEG_3_0, true);
  Set3Seg0124(SEG_3_1, true);
  Set3Seg0124(SEG_3_2, true);
  Set3Seg0124(SEG_3_4, true);
  Set3Seg356(true, true, true);
}

void SetSEGDown() {
  // 字段显示复位
  seg05up = false;
  seg03up = false;
  seg06up = false;

  seg15up = false;
  seg13up = false;
  seg16up = false;

  seg25up = false;
  seg23up = false;
  seg26up = false;

  seg35up = false;
  seg33up = false;
  seg36up = false;

  pwm0.setPWM(SEG_0_0, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm0.setPWM(SEG_0_1, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm0.setPWM(SEG_0_2, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm0.getPWM(SEG_0_6, true) > SERVO_90_A) {
    pwm0.setPWM(SEG_0_3, 0, SERVO_135_R);
    delay(DELAY_SEC);
  }
  pwm0.setPWM(SEG_0_4, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm0.getPWM(SEG_0_6, true) > SERVO_90_A) {
    pwm0.setPWM(SEG_0_5, 0, SERVO_135_A);
    delay(3 * DELAY_SEC);
  }
  pwm0.setPWM(SEG_0_6, 0, SERVO_0_A);
  pwm0.setPWM(SEG_0_R, 0, SERVO_0_R);
  delay(3 * DELAY_SEC);
  pwm0.setPWM(SEG_0_3, 0, SERVO_0_R);
  delay(DELAY_SEC);
  pwm0.setPWM(SEG_0_5, 0, SERVO_0_A);
  delay(DELAY_SEC);

  pwm0.setPWM(SEG_1_0, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm0.setPWM(SEG_1_1, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm0.setPWM(SEG_1_2, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm0.getPWM(SEG_1_6, true) > SERVO_90_A) {
    pwm0.setPWM(SEG_1_3, 0, SERVO_135_R);
    delay(DELAY_SEC);
  }
  pwm0.setPWM(SEG_1_4, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm0.getPWM(SEG_1_6, true) > SERVO_90_A) {
    pwm0.setPWM(SEG_1_5, 0, SERVO_135_A);
    delay(3 * DELAY_SEC);
  }
  pwm0.setPWM(SEG_1_6, 0, SERVO_0_A);
  pwm0.setPWM(SEG_1_R, 0, SERVO_0_R);
  delay(3 * DELAY_SEC);
  pwm0.setPWM(SEG_1_3, 0, SERVO_0_R);
  delay(DELAY_SEC);
  pwm0.setPWM(SEG_1_5, 0, SERVO_0_A);
  delay(DELAY_SEC);

  pwm1.setPWM(SEG_2_0, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm1.setPWM(SEG_2_1, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm1.setPWM(SEG_2_2, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm1.getPWM(SEG_2_6, true) > SERVO_90_A) {
    pwm1.setPWM(SEG_2_3, 0, SERVO_135_R);
    delay(DELAY_SEC);
  }
  pwm1.setPWM(SEG_2_4, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm1.getPWM(SEG_2_6, true) > SERVO_90_A) {
    pwm1.setPWM(SEG_2_5, 0, SERVO_135_A);
    delay(3 * DELAY_SEC);
  }
  pwm1.setPWM(SEG_2_6, 0, SERVO_0_A);
  pwm1.setPWM(SEG_2_R, 0, SERVO_0_R);
  delay(3 * DELAY_SEC);
  pwm1.setPWM(SEG_2_3, 0, SERVO_0_R);
  delay(DELAY_SEC);
  pwm1.setPWM(SEG_2_5, 0, SERVO_0_A);
  delay(DELAY_SEC);

  pwm1.setPWM(SEG_3_0, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm1.setPWM(SEG_3_1, 0, SERVO_0_A);
  delay(DELAY_SEC);
  pwm1.setPWM(SEG_3_2, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm1.getPWM(SEG_3_6, true) > SERVO_90_A) {
    pwm1.setPWM(SEG_3_3, 0, SERVO_135_R);
    delay(DELAY_SEC);
  }
  pwm1.setPWM(SEG_3_4, 0, SERVO_0_R);
  delay(DELAY_SEC);
  if (pwm1.getPWM(SEG_3_6, true) > SERVO_90_A) {
    pwm1.setPWM(SEG_3_5, 0, SERVO_135_A);
    delay(3 * DELAY_SEC);
  }
  pwm1.setPWM(SEG_3_6, 0, SERVO_0_A);
  pwm1.setPWM(SEG_3_R, 0, SERVO_0_R);
  delay(3 * DELAY_SEC);
  pwm1.setPWM(SEG_3_3, 0, SERVO_0_R);
  delay(DELAY_SEC);
  pwm1.setPWM(SEG_3_5, 0, SERVO_0_A);
  delay(DELAY_SEC);
}

void CheckOFFSET() {
  if (OFFSET_UP_0_0 < OFFSET_MIN) { OFFSET_UP_0_0 = OFFSET_MIN; }
  if (OFFSET_UP_0_1 < OFFSET_MIN) { OFFSET_UP_0_1 = OFFSET_MIN; }
  if (OFFSET_UP_0_2 < OFFSET_MIN) { OFFSET_UP_0_2 = OFFSET_MIN; }
  if (OFFSET_UP_0_3 < OFFSET_MIN) { OFFSET_UP_0_3 = OFFSET_MIN; }
  if (OFFSET_UP_0_4 < OFFSET_MIN) { OFFSET_UP_0_4 = OFFSET_MIN; }
  if (OFFSET_UP_0_5 < OFFSET_MIN) { OFFSET_UP_0_5 = OFFSET_MIN; }
  if (OFFSET_UP_0_6 < OFFSET_MIN) { OFFSET_UP_0_6 = OFFSET_MIN; }
  //
  if (OFFSET_UP_1_0 < OFFSET_MIN) { OFFSET_UP_1_0 = OFFSET_MIN; }
  if (OFFSET_UP_1_1 < OFFSET_MIN) { OFFSET_UP_1_1 = OFFSET_MIN; }
  if (OFFSET_UP_1_2 < OFFSET_MIN) { OFFSET_UP_1_2 = OFFSET_MIN; }
  if (OFFSET_UP_1_3 < OFFSET_MIN) { OFFSET_UP_1_3 = OFFSET_MIN; }
  if (OFFSET_UP_1_4 < OFFSET_MIN) { OFFSET_UP_1_4 = OFFSET_MIN; }
  if (OFFSET_UP_1_5 < OFFSET_MIN) { OFFSET_UP_1_5 = OFFSET_MIN; }
  if (OFFSET_UP_1_6 < OFFSET_MIN) { OFFSET_UP_1_6 = OFFSET_MIN; }
  //
  if (OFFSET_UP_2_0 < OFFSET_MIN) { OFFSET_UP_2_0 = OFFSET_MIN; }
  if (OFFSET_UP_2_1 < OFFSET_MIN) { OFFSET_UP_2_1 = OFFSET_MIN; }
  if (OFFSET_UP_2_2 < OFFSET_MIN) { OFFSET_UP_2_2 = OFFSET_MIN; }
  if (OFFSET_UP_2_3 < OFFSET_MIN) { OFFSET_UP_2_3 = OFFSET_MIN; }
  if (OFFSET_UP_2_4 < OFFSET_MIN) { OFFSET_UP_2_4 = OFFSET_MIN; }
  if (OFFSET_UP_2_5 < OFFSET_MIN) { OFFSET_UP_2_5 = OFFSET_MIN; }
  if (OFFSET_UP_2_6 < OFFSET_MIN) { OFFSET_UP_2_6 = OFFSET_MIN; }
  //
  if (OFFSET_UP_3_0 < OFFSET_MIN) { OFFSET_UP_3_0 = OFFSET_MIN; }
  if (OFFSET_UP_3_1 < OFFSET_MIN) { OFFSET_UP_3_1 = OFFSET_MIN; }
  if (OFFSET_UP_3_2 < OFFSET_MIN) { OFFSET_UP_3_2 = OFFSET_MIN; }
  if (OFFSET_UP_3_3 < OFFSET_MIN) { OFFSET_UP_3_3 = OFFSET_MIN; }
  if (OFFSET_UP_3_4 < OFFSET_MIN) { OFFSET_UP_3_4 = OFFSET_MIN; }
  if (OFFSET_UP_3_5 < OFFSET_MIN) { OFFSET_UP_3_5 = OFFSET_MIN; }
  if (OFFSET_UP_3_6 < OFFSET_MIN) { OFFSET_UP_3_6 = OFFSET_MIN; }
  // MAX
  if (OFFSET_UP_0_0 > OFFSET_MAX) { OFFSET_UP_0_0 = OFFSET_MAX; }
  if (OFFSET_UP_0_1 > OFFSET_MAX) { OFFSET_UP_0_1 = OFFSET_MAX; }
  if (OFFSET_UP_0_2 > OFFSET_MAX) { OFFSET_UP_0_2 = OFFSET_MAX; }
  if (OFFSET_UP_0_3 > OFFSET_MAX) { OFFSET_UP_0_3 = OFFSET_MAX; }
  if (OFFSET_UP_0_4 > OFFSET_MAX) { OFFSET_UP_0_4 = OFFSET_MAX; }
  if (OFFSET_UP_0_5 > OFFSET_MAX) { OFFSET_UP_0_5 = OFFSET_MAX; }
  if (OFFSET_UP_0_6 > OFFSET_MAX) { OFFSET_UP_0_6 = OFFSET_MAX; }
  //
  if (OFFSET_UP_1_0 > OFFSET_MAX) { OFFSET_UP_1_0 = OFFSET_MAX; }
  if (OFFSET_UP_1_1 > OFFSET_MAX) { OFFSET_UP_1_1 = OFFSET_MAX; }
  if (OFFSET_UP_1_2 > OFFSET_MAX) { OFFSET_UP_1_2 = OFFSET_MAX; }
  if (OFFSET_UP_1_3 > OFFSET_MAX) { OFFSET_UP_1_3 = OFFSET_MAX; }
  if (OFFSET_UP_1_4 > OFFSET_MAX) { OFFSET_UP_1_4 = OFFSET_MAX; }
  if (OFFSET_UP_1_5 > OFFSET_MAX) { OFFSET_UP_1_5 = OFFSET_MAX; }
  if (OFFSET_UP_1_6 > OFFSET_MAX) { OFFSET_UP_1_6 = OFFSET_MAX; }
  //
  if (OFFSET_UP_2_0 > OFFSET_MAX) { OFFSET_UP_2_0 = OFFSET_MAX; }
  if (OFFSET_UP_2_1 > OFFSET_MAX) { OFFSET_UP_2_1 = OFFSET_MAX; }
  if (OFFSET_UP_2_2 > OFFSET_MAX) { OFFSET_UP_2_2 = OFFSET_MAX; }
  if (OFFSET_UP_2_3 > OFFSET_MAX) { OFFSET_UP_2_3 = OFFSET_MAX; }
  if (OFFSET_UP_2_4 > OFFSET_MAX) { OFFSET_UP_2_4 = OFFSET_MAX; }
  if (OFFSET_UP_2_5 > OFFSET_MAX) { OFFSET_UP_2_5 = OFFSET_MAX; }
  if (OFFSET_UP_2_6 > OFFSET_MAX) { OFFSET_UP_2_6 = OFFSET_MAX; }
  //
  if (OFFSET_UP_3_0 > OFFSET_MAX) { OFFSET_UP_3_0 = OFFSET_MAX; }
  if (OFFSET_UP_3_1 > OFFSET_MAX) { OFFSET_UP_3_1 = OFFSET_MAX; }
  if (OFFSET_UP_3_2 > OFFSET_MAX) { OFFSET_UP_3_2 = OFFSET_MAX; }
  if (OFFSET_UP_3_3 > OFFSET_MAX) { OFFSET_UP_3_3 = OFFSET_MAX; }
  if (OFFSET_UP_3_4 > OFFSET_MAX) { OFFSET_UP_3_4 = OFFSET_MAX; }
  if (OFFSET_UP_3_5 > OFFSET_MAX) { OFFSET_UP_3_5 = OFFSET_MAX; }
  if (OFFSET_UP_3_6 > OFFSET_MAX) { OFFSET_UP_3_6 = OFFSET_MAX; }
}

void SaveEeprom() {
  CheckOFFSET();

  EEPROM.write(0, OFFSET_UP_0_0);
  EEPROM.write(1, OFFSET_UP_0_1);
  EEPROM.write(2, OFFSET_UP_0_2);
  EEPROM.write(3, OFFSET_UP_0_3);
  EEPROM.write(4, OFFSET_UP_0_4);
  EEPROM.write(5, OFFSET_UP_0_5);
  EEPROM.write(6, OFFSET_UP_0_6);
  //
  EEPROM.write(10, OFFSET_UP_1_0);
  EEPROM.write(11, OFFSET_UP_1_1);
  EEPROM.write(12, OFFSET_UP_1_2);
  EEPROM.write(13, OFFSET_UP_1_3);
  EEPROM.write(14, OFFSET_UP_1_4);
  EEPROM.write(15, OFFSET_UP_1_5);
  EEPROM.write(16, OFFSET_UP_1_6);
  //
  EEPROM.write(20, OFFSET_UP_2_0);
  EEPROM.write(21, OFFSET_UP_2_1);
  EEPROM.write(22, OFFSET_UP_2_2);
  EEPROM.write(23, OFFSET_UP_2_3);
  EEPROM.write(24, OFFSET_UP_2_4);
  EEPROM.write(25, OFFSET_UP_2_5);
  EEPROM.write(26, OFFSET_UP_2_6);
  //
  EEPROM.write(30, OFFSET_UP_3_0);
  EEPROM.write(31, OFFSET_UP_3_1);
  EEPROM.write(32, OFFSET_UP_3_2);
  EEPROM.write(33, OFFSET_UP_3_3);
  EEPROM.write(34, OFFSET_UP_3_4);
  EEPROM.write(35, OFFSET_UP_3_5);
  EEPROM.write(36, OFFSET_UP_3_6);
  //
  EEPROM.commit();
}

void SetEeprom() {
  if (SET_DEFAULT != 100) {
    SET_DEFAULT = 100;
    //
    OFFSET_UP_0_0 = 100;
    OFFSET_UP_0_1 = 100;
    OFFSET_UP_0_2 = 100;
    OFFSET_UP_0_3 = 100;
    OFFSET_UP_0_4 = 100;
    OFFSET_UP_0_5 = 100;
    OFFSET_UP_0_6 = 100;
    //
    OFFSET_UP_1_0 = 100;
    OFFSET_UP_1_1 = 100;
    OFFSET_UP_1_2 = 100;
    OFFSET_UP_1_3 = 100;
    OFFSET_UP_1_4 = 100;
    OFFSET_UP_1_5 = 100;
    OFFSET_UP_1_6 = 100;
    //
    OFFSET_UP_2_0 = 100;
    OFFSET_UP_2_1 = 100;
    OFFSET_UP_2_2 = 100;
    OFFSET_UP_2_3 = 100;
    OFFSET_UP_2_4 = 100;
    OFFSET_UP_2_5 = 100;
    OFFSET_UP_2_6 = 100;
    //
    OFFSET_UP_3_0 = 100;
    OFFSET_UP_3_1 = 100;
    OFFSET_UP_3_2 = 100;
    OFFSET_UP_3_3 = 100;
    OFFSET_UP_3_4 = 100;
    OFFSET_UP_3_5 = 100;
    OFFSET_UP_3_6 = 100;
    //
    EEPROM.write(255, SET_DEFAULT);
    //
    SaveEeprom();
  } else {
    OFFSET_UP_0_0 = EEPROM.read(0);
    OFFSET_UP_0_1 = EEPROM.read(1);
    OFFSET_UP_0_2 = EEPROM.read(2);
    OFFSET_UP_0_3 = EEPROM.read(3);
    OFFSET_UP_0_4 = EEPROM.read(4);
    OFFSET_UP_0_5 = EEPROM.read(5);
    OFFSET_UP_0_6 = EEPROM.read(6);
    //
    OFFSET_UP_1_0 = EEPROM.read(10);
    OFFSET_UP_1_1 = EEPROM.read(11);
    OFFSET_UP_1_2 = EEPROM.read(12);
    OFFSET_UP_1_3 = EEPROM.read(13);
    OFFSET_UP_1_4 = EEPROM.read(14);
    OFFSET_UP_1_5 = EEPROM.read(15);
    OFFSET_UP_1_6 = EEPROM.read(16);
    //
    OFFSET_UP_2_0 = EEPROM.read(20);
    OFFSET_UP_2_1 = EEPROM.read(21);
    OFFSET_UP_2_2 = EEPROM.read(22);
    OFFSET_UP_2_3 = EEPROM.read(23);
    OFFSET_UP_2_4 = EEPROM.read(24);
    OFFSET_UP_2_5 = EEPROM.read(25);
    OFFSET_UP_2_6 = EEPROM.read(26);
    //
    OFFSET_UP_3_0 = EEPROM.read(30);
    OFFSET_UP_3_1 = EEPROM.read(31);
    OFFSET_UP_3_2 = EEPROM.read(32);
    OFFSET_UP_3_3 = EEPROM.read(33);
    OFFSET_UP_3_4 = EEPROM.read(34);
    OFFSET_UP_3_5 = EEPROM.read(35);
    OFFSET_UP_3_6 = EEPROM.read(36);
  }
  CheckOFFSET();
}
#endif